//
//  LGMainController.swift
//  longWeb
//
//  Created by 叶剑龙 on 15/12/15.
//  Copyright © 2015年 cn.long. All rights reserved.
//

import UIKit

class LGMainController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //自定义tabbar
        let mainTabBar = LGMainTabBar()
        setValue(mainTabBar, forKey: "tabBar")
        
        //首页
        let homeVc = LGHomeController()
        self.addChildVC(homeVc, title: "首页", imageName: "tabbar_home")
        //消息
        let messageVc = LGMessageController()
        self.addChildVC(messageVc, title: "消息", imageName: "tabbar_message_center")
        //发现
        let discoveryVc = LGDiscoveryController()
        self.addChildVC(discoveryVc, title: "发现", imageName: "tabbar_discover")
        //我
        let profileVc = LGProfileController()
        self.addChildVC(profileVc, title: "我", imageName: "tabbar_profile")
    }
    
    /**
     添加子控制器
     
     :param: controller 控制器
     :param: title      标题
     :param: imageName  图片
     */
    private func addChildVC(controller: UIViewController, title: String, imageName: String) {
        //包装导航控制器
        self.addChildViewController(UINavigationController(rootViewController: controller))
        //设置title
        controller.title = title
        //设置图片
        controller.tabBarItem.image = UIImage(named: imageName)
        //设置高亮图片
        let selectedImage = imageName + "_highlighted"
        controller.tabBarItem.selectedImage = UIImage(named: selectedImage)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        //设置文字颜色
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
    }

    
    
  
   
}
